<?php

/**
 * 直播模块
 *
 * Created by PhpStorm.
 * User: evan
 * Date: 2016/12/13
 * Time: 上午11:30
 */
class Direct_seeding extends MY_M_Controller
{
    /**
     * 开启直播
     */
    public function start()
    {
        $ds_id = (int)$this->input->get_post('ds_id');


        if (!$ds_id)
        {
            show_error('参数不全!');
        }


        $this->load->model('direct_seeding/Model_direct_seeding', 'ds');
        $item = $this->ds->getById($ds_id);


        if (empty($item))
        {
            show_error('直播不存在!');
        }


        $this->load->model('user/Model_user', 'u');
        $user_item = $this->u->get_by_uid($item['anchor_uid'], true);
        if (empty($user_item))
        {
            show_error('主播用户不存在');
        }


        $data = array
        (
            'item' => $item,
            'user_item' => $user_item['data'],
        );


        $this->load->view('m/direct_seeding/start', $data);
    }


    /**
     * 直播中
     */
    public function doing()
    {
        $ds_id = (int)$this->input->get_post('ds_id');


        if (!$ds_id)
        {
            show_error('参数不全!');
        }


        $this->load->model('direct_seeding/Model_direct_seeding', 'ds');
        $item = $this->ds->getById($ds_id);


        if (empty($item))
        {
            show_error('直播不存在!');
        }


        $this->load->model('user/Model_user', 'u');
        $user_item = $this->u->get_by_uid($item['anchor_uid'], true);
        if (empty($user_item))
        {
            show_error('主播用户不存在');
        }


        $data = array
        (
            'item' => $item,
            'user_item' => $user_item['data'],
        );


        $this->load->view('m/direct_seeding/doing', $data);
    }


    /**
     * 直播结束
     */
    public function finish()
    {
        $ds_id = (int)$this->input->get_post('ds_id');


        if (!$ds_id)
        {
            show_error('参数不全!');
        }


        $this->load->model('direct_seeding/Model_direct_seeding', 'ds');
        $item = $this->ds->getById($ds_id);


        if (empty($item))
        {
            show_error('直播不存在!');
        }


        $this->load->model('user/Model_user', 'u');
        $user_item = $this->u->get_by_uid($item['anchor_uid'], true);
        if (empty($user_item))
        {
            show_error('主播用户不存在');
        }


        $data = array
        (
            'item' => $item,
            'user_item' => $user_item['data'],
        );


        $this->load->view('m/direct_seeding/finish', $data);
    }
    
    /**
     * 直播详情
     */
    public function detail()
    {
        $ds_id = (int)$this->input->get_post('ds_id');


        if (!$ds_id)
        {
            show_error('参数不全!');
        }


        $this->load->model('direct_seeding/Model_direct_seeding', 'ds');
        $item = $this->ds->getById($ds_id);


        if (empty($item))
        {
            show_error('直播不存在!');
        }


        $this->load->model('user/Model_user', 'u');
        $user_item = $this->u->get_by_uid($item['anchor_uid'], true);
        if (empty($user_item))
        {
            show_error('主播用户不存在');
        }


        $data = array
        (
            'item' => $item,
            'user_item' => $user_item['data'],
        );


        if($item['status'] == DS_STATUS_DOING)
        {
            $this->load->view('m/direct_seeding/doing', $data);
        }
        else
        {
            $this->load->view('m/direct_seeding/finish', $data);
        }
    }
}